
{extend name="admin@publics/base"/}
{block name="title"}日志管理{/block}
{block name="body"}

<script>
//页面变量
_PAGE['adminActionLog'] = {
};
/*==========控制器==========*/
Ext.define('admin.action_log.CURDViewController', {
	extend: 'Tg.tx.CURDViewController',
	alias: 'controller._adminActionLogController',
	//行双击
	_ItemDbClick:function(_Obj,_Record,item,index,e,eOpts ){
		var _Me	= this;
		if(!_Me._CheckAuth('look')){return false;}
		var _V	= _Me.getView();
		var _VM	= _V.getViewModel();
		var _Grid = _V.down('gridpanel');
		if(!_Grid){
			_Grid = _V.down('treepanel');
		}
        var _Select =_Grid.selModel.getSelection();
        _Grid.selModel.deselect(_Select);
		_Grid.selModel.select(index,true);
		_V.down('toolbar button#_Look').click();
	},
    //根据grid控制顶部按钮显示隐藏
    _SelectChange:function(model, selected, eOpts){
		var _Me = this;
		var _V	= _Me.getView();
		var _VM	= _V.getViewModel();
		if(_VM.get('_Auth.look') && _V.down('toolbar button#_Look')){
    		_V.down('toolbar button#_Look')[selected.length == 1 ? 'enable' : 'disable']();
		}
		//子类继承此方法必须执行
		//this.callParent(); 
    },
    //删除
    _Dels:function(button, e, eOpts){
		var _Me	= this;
		if(!_Me._CheckAuth('dels')){return false;}
		var _V	= _Me.getView();
		var _VM	= _V.getViewModel();
		var _Store = _VM.get('_MainStore');
		var _Url = _VM.get('_Url.del');
        var _Return	= Ext.create('Tg.tx.Action').doAction({params:{t:button.t},url:_Url,store:_Store})
    },
});
/*==========模型==========*/
Ext.define('admin.action_log.CURDViewModel', {
	extend: 'Tg.tx.CURDViewModel',
	alias: 'viewmodel._adminActionLogViewModel',
    //Data
    data:{
    	//权限
        _Auth:{
        	index	: {if condition="_CheckAuth('admin/ActionLog/index')"}true{else/}false{/if},
        	dels	: {if condition="_CheckAuth('admin/ActionLog/del')"}true{else/}false{/if},
        	look	: {if condition="_CheckAuth('admin/ActionLog/look')"}true{else/}false{/if},
        },
        _Url:{
        	index	: _PATH['site']+'/admin/action_log/index',
        	del		: _PATH['site']+'/admin/action_log/del',
        	look	: _PATH['site']+'/admin/action_log/look',
        },
        //操作视图
        _Ext:{
        	index	: 'admin.action_log.index',
        	serch	: 'admin.action_log.serch',
        	del		: 'admin.action_log.del',
        	look	: 'admin.action_log.look',
        },
		_Pk:'id',
    },
    //Store
	stores: {
		_MainStore: {
			sorters: [{property: 'id',direction: 'desc'}],
			pageSize: 20,
			remoteSort: true,
			remoteFilter:true,
			proxy: {
				type: 'ajax',
				api: {read:_PATH['site']+'/admin/action_log/index'},
				actionMethods:{read: "POST"},
				reader: {type: 'json',rootProperty: 'rows',totalProperty: 'total'}
			},
		}
	},
});
/*==========视图==========*/
//列表
Ext.define('admin.action_log.index', {
	extend: 'Tg.tx.CURDList',
	alias: 'widget.admin_ActionLog_index',
	requires: [
		'admin.action_log.CURDViewController',
		'admin.action_log.CURDViewModel',
	],
	controller: '_adminActionLogController',
	viewModel: '_adminActionLogViewModel',
    _TbarLBefore:[
        {xtype: 'label',text: '日志管理',itemId:'_Tit',style: 'font-size:16px; padding-right:10px;margin-right: 10px;border-right: dotted 1px #ccc;'},
    ],
    _TbarRBefore:[
        {text: '清除',itemId:'_Dels',iconCls: 'tf tf-del',bind:{hidden:'{!_Auth.dels}'},defaults:{xtype: 'menuitem'},menu: {
            xtype: 'menu',
            items: [
                {text: '本月前',handler: "_Dels",t:'m'},
                {text: '1年前',handler: "_Dels",t:'y'},
                {text: '全部',handler: "_Dels",t:'a'},
            ]
        }},
    ],
    items:[
		{
			xtype:'CURDListGrid',
			bind:{store:'{_MainStore}'},
			columns:[
				{xtype:"actioncolumn",header:"查看",width: 50,iconCls:'tf tf-look',align:'center',locked: true,handler: '_ColumnLook',bind:{hidden:'{!_Auth.look}'}},
				{dataIndex:'id', header :'主键', width :60, hidden:false, locked:true, sortable:true },
				{dataIndex : "action_name",header : "标识",width :120, hidden:false, locked:true, sortable:false},
				{dataIndex : "action_title",header : "行为",width :120, hidden:false, locked:true, sortable:false},
				{dataIndex:'user_name', header :'执行者[用户名][ID]', width :400, hidden:false, locked:false, sortable:false },
				{dataIndex:'action_ip', header :'执行者IP', width :120, hidden:false, locked:false, sortable:false },
				{dataIndex:'model', header :'触发数据表', width :120, hidden:true, locked:false, sortable:false },
				{dataIndex:'record_id', header :'触发数据ID', width :120, hidden:true, locked:false, sortable:false },
				{dataIndex:'create_time', header :'触发时间', width :110, hidden:false, locked:false, sortable:true },
			],
		}
	],
});

//搜索
Ext.define('admin.action_log.serch', {
	extend: 'Tg.tx.Window',
	alias: 'widget.admin_ActionLog_serch',
	requires: [
		'admin.action_log.CURDViewController',
		'admin.action_log.CURDViewModel',
	],
	controller: '_adminActionLogController',
	viewModel: '_adminActionLogViewModel',
    title:'搜索',
    items:{
    	xtype:'CURDForm',
        items:[ 
			{items: [
				{fieldLabel: '主键', name: 's_id',xtype: "textfield", columnWidth: 0.5},
				{fieldLabel: '行为ID', name: 's_action_id',xtype: "textfield", columnWidth: 0.5},
			]},
			{items: [
				{fieldLabel: '执行者ID', name: 's_user_id',xtype: "textfield", columnWidth: 0.5},
				{fieldLabel: '执行者IP', name: 's_action_ip',xtype: "textfield", columnWidth: 0.5},
			]},
			{items: [
				{fieldLabel: '触发数据表', name: 's_model',xtype: "textfield", columnWidth: 0.5},
				{fieldLabel: '触发数据ID', name: 's_record_id',xtype: "textfield", columnWidth: 0.5},
			]},
			{items: [
				{fieldLabel: '日志备注', name: 's_remark',xtype: "textfield"},
			]},
			{items: [
				{fieldLabel: '起始触发时间', name: 's_create_time_min',xtype: "datetimefield",columnWidth: 0.5},
				{fieldLabel: '截止触发时间', name: 's_create_time_max',xtype: "datetimefield",columnWidth: 0.5},
			]},
        ]
    }
});

//查看 
Ext.define('admin.action_log.look', {
	extend: 'Tg.tx.Window',
	alias: 'widget.admin_ActionLog_look',
	requires: [
		'admin.action_log.CURDViewController',
		'admin.action_log.CURDViewModel',
	],
	controller: '_adminActionLogController',
	viewModel: '_adminActionLogViewModel',
    title:'日志 - 查看',
    items:{
    	xtype:'CURDForm',
        items:[
			{items: [
				{xtype:'textfield', fieldLabel: '行为ID', name: 'action_id', itemId: 'action_id', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
				{xtype:'datetimefield', fieldLabel: '触发时间', name: 'create_time', itemId: 'create_time', cls: '', columnWidth: 0.5, height: 30, readOnly: true, editable:true, format: 'Y-m-d H:i:s'},
			]},
			{items: [
				{xtype:'textfield', fieldLabel: '行为名称', name: 'action_title', itemId: 'action_title', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
				{xtype:'textfield', fieldLabel: '行为标识', name: 'action_name', itemId: 'action_name', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
			]},
			{items: [
				{xtype:'textfield', fieldLabel: '执行者ID', name: 'user_id', itemId: 'user_id', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
				{xtype:'textfield', fieldLabel: '执行者IP', name: 'action_ip', itemId: 'action_ip', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
			]},
			{items: [
				{xtype:'textfield', fieldLabel: '执行者用户名', name: 'user_name', itemId: 'user_name', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
				{xtype:'textfield', fieldLabel: '执行者姓名', name: 'user_truename', itemId: 'user_truename', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
			]},
			{items: [
				{xtype:'textfield', fieldLabel: '触发数据表', name: 'model', itemId: 'model', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
				{xtype:'textfield', fieldLabel: '触发数据ID', name: 'record_id', itemId: 'record_id', cls: '', columnWidth: 0.5, height: 30, readOnly: true, emptyText:''},
			]},
			{items: [
				{xtype:'textarea', fieldLabel: '日志备注', name: 'remark', itemId: 'remark', cls: '', columnWidth: 1, height: 30, readOnly: true, preventScrollbars:true, emptyText:''},
			]},
			{xtype:'hiddenfield', fieldLabel: '主键', name: 'id', itemId: 'id', cls: '', columnWidth: 1, height: 30, readOnly: true},
        ]
    }
});


//实例化
Ext.application({
	name: 'admin',
	extend: 'Ext.app.Application',
	autoCreateViewport: 'admin.action_log.index'
});
</script>

{/block}
